home *** CD-ROM | disk | FTP | other *** search
/ Java 1996 August / Java - Summer 1996.iso / windows / doc / outputfi.jav < prev    next >
Encoding:
Text File  |  1996-02-26  |  2.4 KB  |  79 lines

  1. /*
  2.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "copyright.html"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  */
  17. /*
  18.  * This file defines class OutputFile which implementa a write-only
  19.  * output file abstraction. Like class InputFile, class OutputFile
  20.  * subclasses of class File to obtain simple file and path name
  21.  * functions.
  22.  */
  23.  
  24. /**
  25.  * This class defines a simple write-only file by extending class File.
  26.  */
  27. public
  28. class OutputFile extends File {
  29.  
  30.     /**
  31.      * Link in the native library that this class depends on. We
  32.      * bind this class loading to the library loading by making the
  33.      * System.loadLibrary() call part of the static initializer for
  34.      * the class. That is, if the loadLibary() call fails this class
  35.      * fails to load.
  36.      */
  37.     static {
  38.     try {
  39.             System.loadLibrary("file");
  40.         } catch (UnsatisfiedLinkError e) {
  41.             System.out.println("can't find your library");
  42.             System.exit(-1);
  43.         }
  44.  
  45.     }
  46.  
  47.     /**
  48.      * Holds the system dependent handle to the file resource.
  49.      */
  50.     protected int fd;
  51.  
  52.     /**
  53.      * Constructor for the output file object. Initializes the
  54.      * parent class with the path name.
  55.      */
  56.     public OutputFile(String path) {
  57.     super(path);
  58.     }
  59.  
  60.     /**
  61.      * Attempts to open the file for writing. If the file does not
  62.      * exist one is created. Returns TRUE on success and FALSE on 
  63.      * failure.
  64.      */
  65.     public native boolean open();
  66.  
  67.     /**
  68.      * Attempts to close the previously opened file. Has
  69.      * no return value.
  70.      */
  71.     public native void close();
  72.  
  73.     /**
  74.      * Writes some number of bytes to the opened file. Returns
  75.      * the number of bytes written.
  76.      */
  77.     public native int write(byte b[], int len);
  78. }
  79.